#!/usr/bin/env python
#-*-coding=utf8-*-


import optparse
import sys
import os

from qiushispiders import create_spider,get_qiushi
from sendmail import send_qiushi_email


def send_qiushi(num,email):
    
    qiushi = get_qiushi(num)
    
    send_qiushi_email(qiushi,'qishibaike',email)


def main():
    parser = optparse.OptionParser()
    parser.add_option('-k','--kill',
            action='store_true',
            default=True,
            dest='stop',
            help="stop spiders"
            )
    parser.add_option('-l','--log',
            action='store',
            default='/var/log/spdiersG',
            dest='log_path',
            help='the path of logs put.')
    parser.add_option('-s','--spiders',
            action='store',
            dest='num_of_spiders',
            type='int',
            default=0,
            help='set the numbers of spiders.')
    parser.add_option('-e','--email',
            action='store',
            dest='email',
            help='send qiushi to email')
    parser.add_option('-n','--number',
            action='store',
            dest='num',
            default=20,
            type='int',
            help='send num of qiushi to email')
    args = sys.argv[1:]

    opts,remain =  parser.parse_args(args)
    num_s = opts.num_of_spiders
    if num_s > 0:
        create_spider(num)
    elif opts.email:
        num_q = opts.num
        send_qiushi(num_q,opts.email)

if __name__ == "__main__":
    main()
